<?php

namespace App\Http\Middleware;

use App\Models\AdminUser;
use App\Models\ShopUser;
use Closure,Session,Auth,Gate;

class ShopAdmin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next,$test='')
    {

        //判断是否有管理员登录
        if (Auth::check() && !empty(Session::get('userShopId')) && ShopUser::where('shop_id', Session::get('userShopId'))->where('user_id', Auth::user()->id)->count()){

            return $next($request);

        }else{

            if ($request->ajax()){

                return response()->json(['message'=>'用户没有登录'],403);

            }else{

                return redirect()->route('shop_admin.login.index');

            }
        }

    }
}
